include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories($ENV{HOME}/include)
include_directories(.)
include_directories(util)
include_directories(cfg)

LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/lib)

if(IBMMQ_SUPPORT)
    include_directories(/opt/mqm/inc)
endif()

if(OPENSSL_SUPPORT)
    add_definitions(-DCPPHTTPLIB_OPENSSL_SUPPORT)
endif()

set (SRCS
   ${PROJECT_SOURCE_DIR}/include/pugixml/pugixml.hpp
   ${PROJECT_SOURCE_DIR}/include/pugixml/pugixml.cpp
   ${PROJECT_SOURCE_DIR}/include/pugixml/pugiconfig.hpp  
    util/topconn_string.cpp
    util/topconn_logutil.cpp
    cfg/topconn_cfg_loader.cpp
    cfg/topconn_cfg_parser.cpp
    topconn_executor.cpp
    topconn_factory.cpp
    topconn_helper.cpp 
    topconn_processor.cpp
    topconn_component.cpp
    )

set (PROTOCAL_SRC 
    protocal/tcp/sockutil.cpp
    protocal/tcp/tcpclient.cpp
    protocal/tcp/tcpconnector.cpp
    protocal/udp/udphelper.cpp
    protocal/udp/udpclient.cpp
    protocal/udp/udpconnector.cpp
    protocal/http/httpclient.cpp
    protocal/http/httpconnector.cpp
    protocal/mq/posix/posix_queue.cpp
    protocal/mq/posix/posixconnector.cpp
)

##openssl support
if(OPENSSL_SUPPORT)
    set(PROTOCAL_SRC ${PROTOCAL_SRC}
        protocal/https/httpsclient.cpp
        protocal/https/httpsconnector.cpp
        protocal/tcp_ssl/ssl_util.cpp
        protocal/tcp_ssl/ssl_tcpclient.cpp
        protocal/tcp_ssl/ssl_tcpconnector.cpp
    )
endif()

##cibctsp support
if(CIBCTSP_SUPPORT)
    set(PROTOCAL_SRC ${PROTOCAL_SRC}
        protocal/ctsp/tcpcom.c
        protocal/ctsp/ctspclient.cpp
        protocal/ctsp/ctspconnector.cpp
    )
endif()

##ibmmq support
if(IBMMQ_SUPPORT)
    set(PROTOCAL_SRC ${PROTOCAL_SRC}
        protocal/mq/ibm/mqmclient.cpp
        protocal/mq/ibm/mqconnector.cpp
    )
endif()

##sftp support
if(SSH_SFTP_SUPPORT)
    set(PROTOCAL_SRC ${PROTOCAL_SRC}
        protocal/sftp/sftpclient.cpp
        protocal/sftp/sftpconnector.cpp
    )
endif()

#set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
add_library(topconn SHARED ${SRCS} ${PROTOCAL_SRC})
if(ENABLE_USE_LOGCPLUS)
    target_link_libraries(topconn logcplus)
endif() 
if(OPENSSL_SUPPORT)
   target_link_libraries(topconn ssl crypto)
endif()
if(IBMMQ_SUPPORT)
    target_link_libraries(topconn imqc23gl imqb23gl mqic)
endif()
if(SSH_SFTP_SUPPORT)
   target_link_libraries(topconn ssh2)
endif()
target_link_libraries(topconn rt)
install(TARGETS topconn DESTINATION ${LIBRARY_INSTALL_PATH})

if(IBMMQ_SUPPORT)
add_executable(topconn_mqput protocal/mq/ibm/mqclientput.cpp )
target_link_libraries(topconn_mqput topconn)
add_executable(topconn_mqget protocal/mq/ibm/mqclientget.cpp )
target_link_libraries(topconn_mqget topconn)
install(TARGETS topconn_mqput  topconn_mqget DESTINATION ${EXECUTABLE_INSTALL_PATH})
endif()

add_executable(topconn_tcpsend protocal/tcp/tcpsend.cpp )
target_link_libraries(topconn_tcpsend topconn)
install(TARGETS topconn_tcpsend  DESTINATION ${EXECUTABLE_INSTALL_PATH})

set (HEADERS
    util/topconn_string.hpp
    util/topconn_logutil.hpp
    topconn_cross_platform.hpp
    topconn_error.hpp
    topconn_exception.hpp
    topconn_component.hpp
    topconn.hpp
    )
install(FILES ${HEADERS} DESTINATION ${INCLUDE_INSTALL_PATH}/topconn)

install(FILES 
    protocal/tcp/tcpclient.hpp
    protocal/tcp/sockutil.h
    DESTINATION ${INCLUDE_INSTALL_PATH}/topconn/protocal/tcp)

install(FILES 
    protocal/http/httpclient.hpp
    protocal/http/httplib.h
    DESTINATION ${INCLUDE_INSTALL_PATH}/topconn/protocal/http)

install(FILES 
    protocal/https/httpsclient.hpp
    DESTINATION ${INCLUDE_INSTALL_PATH}/topconn/protocal/https)

install(FILES 
    protocal/udp/udpclient.hpp
    DESTINATION ${INCLUDE_INSTALL_PATH}/topconn/protocal/udp)

install(FILES 
    protocal/mq/ibm/mqmclient.hpp
    DESTINATION ${INCLUDE_INSTALL_PATH}/topconn/protocal/mq/ibm)

install(FILES 
    protocal/mq/posix/posix_queue.hpp
    DESTINATION ${INCLUDE_INSTALL_PATH}/topconn/protocal/mq/posix)

install(FILES 
    protocal/ctsp/ctspclient.hpp
    DESTINATION ${INCLUDE_INSTALL_PATH}/topconn/protocal/ctsp)

install(FILES 
    protocal/sftp/sftpclient.hpp
    DESTINATION ${INCLUDE_INSTALL_PATH}/topconn/protocal/sftp)